/*
Section: Balance tests for IEB
Content: Table G.1
Paper: "Immigrants Return Intentions and Labor Market Behavior when the Home Country is Unsafe"
Journal: Journal of Labor Economics
Authors: Jacopo Bassetto, Teresa Freitas-Monteiro
*/

********************************************************************************
**# LOAD ANALYSIS DATASET
********************************************************************************
	
use "$final/finaldata_ieb_main_light.dta", replace


******************************
**# Figure G.1
******************************
 
* Dummies for education level of the individual 
replace edu_max = 1 if inlist(edu_max,0,.)
tab edu_max, g(education_)


* Firm size in spell before unemployment
cap clonevar ln_firmsize_lb = ln_firmsize


* Plots of joint cov balance

foreach x in m5y m4y m3y {
eststo clear
local i=1

qui eststo mod`i':  reghdfe `out' treatment_terror_`x'_p90 frau age c.ysm_atunemp##c.ysm_atunemp education_2 education_3 ln_wage_any_lb full_time_lb ln_firmsize_lb  share_for_lb_ab_med qualif_hq_lb_ab_med abovemedian_AKM_lb if  register_unemp==1 & k_treatment_terror_`x'_p90_st==1, absorb(i.ieb_nat_id#i.year2 i.month#i.year2 i.state)  vce(cluster clusterterror_`x'_p90)
local i=`i'+1

coefplot mod1, keep(frau age *ysm_atunemp* education_2 education_3 ln_wage_any_lb full_time_lb ln_firmsize_lb  share_for_lb_ab_med qualif_hq_lb_ab_med abovemedian_AKM_lb) ///
horizontal omitted graphregion(color(white)) ///
xline(0, lcolor(cranberry))  coeflabels(frau = "Female" age = "Age" ysm_atunemp="Years since migration" c.ysm_atunemp#c.ysm_atunemp="Years since migration (sq)" education_2 = "Middle edu" education_3 = "Higher edu" ln_wage_any_lb= "Ln hourly wage" full_time_lb = "Full-time employ." ln_firmsize_lb="Ln firm size" share_for_lb_ab_med = "Share Germans (> p50)" qualif_hq_lb_ab_med = "Share HS (> p50)" abovemedian_AKM_lb = "AKM (> p50)")  headings(frau = "{bf:Demographics}" ln_wage_any_lb = "{bf:Labor market outcomes}" ln_firmsize_lb = "{bf:Firm characteristics}")  xscale(r(-0.02(0.01)0.02)) xlabel(-0.02(0.01)0.02, nogrid) ylabel(, nogrid) ciopts(color(navy)) mcolor(navy)


graph save "$graph/ieb_jointcovbalance_`x'_final.gph", replace
graph export "$graph/ieb_jointcovbalance_`x'_final.pdf", as(pdf) replace	
}	





